home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / DOS32VBE.ZIP / DOS32VBE.ASM next >
Encoding:
Assembly Source File  |  1996-12-16  |  5.1 KB  |  245 lines

  1. .386
  2. .model    flat
  3. .stack    1000h
  4. .code
  5.  
  6. lowmemptr    dd    ?
  7. lowmemseg    dw    ?
  8. linearadr    dd    ?
  9. videomem    dd    ?
  10. wgran        dd    ?
  11. vscreen        dd    ?
  12.  
  13. text_success    db    'Success.',13,10,36
  14. text_vbe_error    db    'VESA error.',13,10,36
  15. text_no_mode    db    'The requested video mode is unsupported!',13,10,36
  16. text_no_memory    db    'There is insufficient memory available!',13,10,36
  17.  
  18. _    label
  19. _edi    label    dword
  20. _di    label    word
  21. _dih    db    ?
  22. _dil    db    ?
  23. _edih    db    ?
  24. _edil    db    ?
  25. _esi    label    dword
  26. _si    label    word
  27. _sih    db    ?
  28. _sil    db    ?
  29. _esih    db    ?
  30. _esil    db    ?
  31. _ebp    label    dword
  32. _bp    label    word
  33. _bph    db    ?
  34. _bpl    db    ?
  35. _ebph    db    ?
  36. _ebpl    db    ?
  37. _reserv    dd    ?
  38. _ebx    label    dword
  39. _bx    label    word
  40. _bh    db    ?
  41. _bl    db    ?
  42. _ebh    db    ?
  43. _ebl    db    ?
  44. _edx    label    dword
  45. _dx    label    word
  46. _dh    db    ?
  47. _dl    db    ?
  48. _edh    db    ?
  49. _edl    db    ?
  50. _ecx    label    dword
  51. _cx    label    word
  52. _ch    db    ?
  53. _cl    db    ?
  54. _ech    db    ?
  55. _ecl    db    ?
  56. _eax    label    dword
  57. _ax    label    word
  58. _ah    db    ?
  59. _al    db    ?
  60. _eah    db    ?
  61. _eal    db    ?
  62. _flags    dw    ?
  63. _es    dw    ?
  64. _ds    dw    ?
  65. _fs    dw    ?
  66. _gs    dw    ?
  67. _ip    dw    ?
  68. _cs    dw    ?
  69. _sp    dw    ?
  70. _ss    dw    0
  71.  
  72.  
  73. main:
  74. ;1. Check if the videomode we want is supported on the computer.
  75.    mov     eax,0ee02h
  76.    int     31h
  77.    mov     lowmemseg,ax
  78.    mov     linearadr,ebx
  79.    push    ax      ;\
  80.    xor     eax,eax ; > Clears the high bits of eax
  81.    pop     ax      ;/
  82.    shl     eax,4   ; Makes eax the absolute address of the RM seg
  83.    sub     eax,ebx ; Makes eax a near pointer to the RM segment
  84.    mov     lowmemptr,eax
  85.    mov     eax,0a0000h
  86.    sub     eax,ebx
  87.    mov     videomem,eax
  88.  
  89.    mov     ax,lowmemseg
  90.    mov     _es,ax
  91.    mov     _di,0
  92.    mov     _ax,4f00h
  93.    mov     eax,300h
  94.    mov     ebx,10h
  95.    xor     ecx,ecx
  96.    lea     edi,_           ;our RM callback structure
  97.    int     31h
  98.  
  99.    cmp     _ax,4fh
  100.    jne     vbe_error
  101.    xor     eax,eax
  102.    xor     ebx,ebx
  103.    mov     ax,word ptr lowmemptr[0eh]
  104.    mov     bx,word ptr lowmemptr[10h]
  105.    shl     ebx,4
  106.    add     eax,ebx
  107.    sub     eax,linearadr
  108.    mov     esi,eax
  109.    mov     bx,101h         ;desired video mode
  110. loop1:
  111.    lodsw
  112.    cmp     ax,-1
  113.    je      mode_not_supported
  114.    cmp     ax,bx
  115.    jne     loop1
  116.  
  117. ;2. We need the window granularity of this mode to do proper bankswitching.
  118.    mov     ax,lowmemseg
  119.    mov     _es,ax
  120.    mov     _di,0
  121.    mov     _ax,4f01h
  122.    mov     _cx,101h        ;video mode
  123.    mov     eax,300h
  124.    mov     ebx,10h
  125.    xor     ecx,ecx
  126.    lea     edi,_           ;our RM callback structure
  127.    int     31h
  128.  
  129.    cmp     _ax,4fh
  130.    jne     vbe_error
  131.    xor     ebx,ebx
  132.    mov     bx,word ptr lowmemptr[4]
  133.    shl     ebx,10
  134.    mov     wgran,ebx
  135.  
  136. ;3. Allocate memory for our virtual screen and switch to the SVGA mode.
  137.    mov     eax,0ee42h
  138.    mov     edx,640*480
  139.    int     31h
  140.    jc      not_enough_memory
  141.    mov     vscreen,edx
  142.  
  143.    mov     eax,4f02h
  144.    mov     ebx,101h        ;our video mode..
  145.    int     10h
  146.  
  147. ;4. Put something on the virtual screen.
  148.    mov     edi,vscreen
  149.    xor     eax,eax
  150.    mov     ebx,480
  151. drawloop1:          
  152.    mov     ecx,640/4
  153.    rep     stosd
  154. drawlabel1:
  155.    inc     eax
  156.    or      eax,eax
  157.    jz      drawlabel1
  158.    add     eax,01010100h
  159.    dec     ebx          
  160.    jnz     drawloop1
  161.  
  162. ;5. Flip the virtual screen out to video memory.
  163.    call    flip
  164.  
  165. ;Wait for keypress, then switch to textmode, and exit to DOS.
  166.    xor     eax,eax
  167.    int     16h
  168.    mov     eax,3
  169.    int     10h
  170.    lea     edx,text_success
  171. exit:
  172.    mov     ah,9
  173.    int     21h
  174.    mov     eax,4c00h
  175.    int     21h
  176.  
  177. vbe_error:
  178.    lea     edx,text_vbe_error
  179.    jmp     exit
  180.  
  181. mode_not_supported:
  182.    lea     edx,text_no_mode
  183.    jmp     exit
  184.  
  185. not_enough_memory:
  186.    lea     edx,text_no_memory
  187.    jmp     exit
  188.  
  189. flip    proc
  190.     push    eax ebx ecx edx esi edi ebp
  191.     xor    dx,dx        ;bank counter
  192.     xor    ebx,ebx        ;used to clear the buffer
  193.     mov    ebp,640*480    ;bytes left to move-counter
  194.     mov    esi,vscreen
  195.     mov    edi,videomem
  196.  
  197. outer_loop:
  198.     call    setbank
  199.     cmp    ebp,65536
  200.     jae    mov64k
  201.     mov    ecx,ebp
  202.     sub    ebp,ecx        ;update counter
  203.     shr    ecx,2        ;divide by 4 to get number of dwords to move
  204.     jmp    loop_start
  205. mov64k:    sub    ebp,65536
  206.     mov    ecx,16384
  207. loop_start:
  208.     mov    eax,[esi]    ;read a dword from the buffer
  209.     mov    [edi],eax    ;and write it to video mem
  210.     mov    [esi],ebx    ;clear the dword in the buffer
  211.     add    esi,4        ;update pointers
  212.     add    edi,4        ;update pointers
  213.     dec    ecx
  214.     jnz    loop_start    ;loop for 16384 times, this will move 65536 bytes..
  215.     inc    edx        ;increase bank counter
  216.     sub    edi,65536
  217.     cmp    ebp,3        ;check if we have more than 3 bytes left, 
  218.     ja    outer_loop    ;if so then jump up
  219.     or    ebp,ebp        ;are we completely done?
  220.     jz    flpbye        ;yes, then quit..
  221.  
  222.     mov    ecx,ebp        ;otherwise, move these bytes to video mem
  223. loop2_start:    ;this loop is used to move the bytes left
  224.     mov    al,[esi]    ;read one byte from buffer
  225.     mov    [edi],al    ;and write to video mem
  226.     mov    [esi],bl    ;clear buffer
  227.     inc    esi        ;increase source pointer
  228.     inc    edi        ;increase destination pointer
  229.     dec    ecx 
  230.     jnz    loop2_start    ;play it again, Sam!
  231. flpbye:    pop    ebp edi esi edx ecx ebx eax
  232.     retn
  233. flip    endp        
  234.  
  235. setbank proc
  236.     push    ax bx dx
  237.     mov     ax,4f05h
  238.     xor     bx,bx
  239.     int     10h
  240.     pop     dx bx ax
  241.     retn
  242. setbank endp
  243.  
  244.     end    main
  245.